<template>
	<x-border title="二维码设置" v-loading="loading" class="qrcode-box">
		<el-form label-position="right">
			<base-edit v-model="viewModel" v-if="viewModel" ref="base_edit"></base-edit>
			<el-form-item class="form-buttom" label-width="250px">
				<el-button type="primary" @click="save" :loading="saveLoading">保存</el-button>
				<el-button type="danger" @click="basePreview" v-if="editFool">生成预览</el-button>
				<el-button type="warning" @click="previousPage" v-if="editFool&false">上一页</el-button>
				<el-button type="danger" @click="nextPage" v-if="editFool&false">下一页</el-button>
			</el-form-item>
		</el-form>
	</x-border>
</template>
<script>
	import baseEdit from './widgets/base_edit.vue'
	import ala from 'ala'
	export default {
		components: {
			baseEdit
		},
		data() {
			return {
				widget: [],
				viewModel: null,
				loading: false,
				saveLoading: false,
				editFool: true
			}
		},
		mounted() {
			this.init()
		},
		methods: {
			async init() {
				this.loading = true
				if (this.$ala.router().query.Id === undefined) {
					this.editFool = false
				} else {
					this.editFool = true
				}
				this.viewModel = await this.$ala.getView('Api/QrCode/GetView', this.$ala.router().query)
				this.loading = false
			},
			async basePreview() {
				this.$nextTick(() => {
					this.$refs.base_edit.basePreview()
				})
			},
			async previousPage() {
				var repones = await this.$ala.httpGet('api/qrcode/PrexById', {
					id: this.viewModel.id,
					createTime: this.viewModel.createTime
				})
				if (repones) {
					this.$route.push('/Admin/QrCode/Edit?Id=' + repones.id)
				}
			},
			async nextPage() {
				var repones = await this.$ala.httpGet('api/qrcode/NextById', {
					id: this.viewModel.id,
					createTime: this.viewModel.createTime
				})
				if (repones) {
					this.$route.push('/Admin/QrCode/Edit?Id=' + repones.id)
				}
			},
			async save() {
				this.saveLoading = true
				var response = await this.$ala.httpPost('api/QrCode/Save', this.viewModel)
				if (response) {
					this.$ala.toMessage(response)
				}
				this.saveLoading = false
			}
		}
	}
</script>
<style el="stylesheet/scss" lang="scss">
	@import "./widgets/var.scss";
</style>